//
//  HomeBizMenusCell.m
//  YYZB
//
//  Created by Tongqingqing on 2017/9/27.
//
//

#import "HomeBizMenusCell.h"
#import <Masonry/Masonry.h>
#import "UIImageView+OnlineImage.h"

@interface HomeBizMenusCell ()<HomeBizMenusBigClassViewDelegte,HomeBizMenusSmallClassViewDelegate>

@end

@implementation HomeBizMenusCell

- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]){
        
    }
    return self;
}

- (void)layoutSubview
{
    [self.bigView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.width.equalTo(self.mas_width).multipliedBy(1/3.f);
        make.bottom.top.equalTo(self);
    }];
    
    [self.smallView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.left.equalTo(self.bigView.mas_right).offset(1.5);
        make.right.equalTo(self.smallView.mas_left).offset(-1.5);
        make.width.equalTo(self.mas_width).multipliedBy(1/3.f).offset(-10-1.5);
        make.bottom.equalTo(self);
    }];
    
    [self.smallView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.left.equalTo(self.smallView1.mas_right).offset(1.5);
        make.right.equalTo(self).offset(-10);
        make.bottom.equalTo(self);
    }];
}

- (void)bindData:(BizMenu *)data
{
//    for (UIView * subview in [self subviews]) {
//        if ([[subview class] isSubclassOfClass:[HomeBizMenusCustomView class]]){
//            [subview removeFromSuperview];
//        }
//    }
    
    [_bigView removeFromSuperview];
    [_smallView1 removeFromSuperview];
    [_smallView removeFromSuperview];
    
    _bigView = nil;
    _smallView = nil;
    _smallView1 = nil;
    
    if(data.subclassArray.count == 0){
        self.smallView1.backgroundColor = [UIColor whiteColor];
    }
    if(data.subclassArray1.count == 0){
        self.smallView.backgroundColor = [UIColor whiteColor];
    }
    self.model = data;
    [self.contentView addSubview:self.bigView];
    [self.contentView addSubview:self.smallView1];
    [self.contentView addSubview:self.smallView];
    [self layoutSubview];
}

#pragma mark --- HomeBizMenusBigClassViewDelegte
- (void)bigClassClickWithModel:(BizMenu *)model
{
    if (_delegate &&
        [self.delegate respondsToSelector:@selector(homeBizMenusCellClickWithModel:withIndex:)]) {
        [_delegate homeBizMenusCellClickWithModel:model withIndex:666666];
    }
}

#pragma mark --- HomeBizMenusSmallClassViewDelegate
- (void)smallClassClickWithModel:(BizMenu *)model withIndex:(NSInteger)index
{
    if (_delegate &&
        [self.delegate respondsToSelector:@selector(homeBizMenusCellClickWithModel:withIndex:)]) {
        [_delegate homeBizMenusCellClickWithModel:model withIndex:index];
    }
}

#pragma mark --- getter and setter
- (HomeBizMenusBigClassView *)bigView
{
    if (!_bigView) {
        _bigView = [[HomeBizMenusBigClassView alloc] initWithModel:self.model];
        _bigView.delegate = self;
    }
    return _bigView;
}

- (HomeBizMenusSmallClassView *)smallView
{
    if (!_smallView) {
        _smallView = [[HomeBizMenusSmallClassView alloc] initWithModel:self.model.subclassArray1];
        _smallView.delegate = self;
        _smallView.tag = 1;
    }
    return _smallView;
}

- (HomeBizMenusSmallClassView *)smallView1
{
    if (!_smallView1) {
        _smallView1 = [[HomeBizMenusSmallClassView alloc] initWithModel:self.model.subclassArray];
        _smallView1.delegate = self;
        _smallView1.tag = 2;
    }
    return _smallView1;
}


@end
